version: "3"

services:
  db:
    container_name: tasklist-postgres
    image: postgres:15.1-alpine
    environment:
      - POSTGRES_USER=${POSTGRES_USERNAME}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DATABASE}
      - TZ=Europe/Moscow
    ports:
      - "5432:5432"
    networks:
      - app-network
    volumes:
      - db:/var/lib/postgresql/data/
    restart: unless-stopped

  cache:
    container_name: tasklist-redis
    image: redis:7.2-alpine
    environment:
      - TZ=Europe/Moscow
    command: redis-server --save 20 1 --loglevel warning --requirepass ${REDIS_PASSWORD}
    ports:
      - "6379:6379"
    networks:
      - app-network
    volumes:
      - cache:/data
    restart: unless-stopped

  app:
    container_name: tasklist-app
    build:
      context: .
      args:
        DOCKER_USER: rootless_user
    env_file:
      - .env
    environment:
      - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/${POSTGRES_DATABASE}?currentSchema=${POSTGRES_SCHEMA}
      - SPRING_DATA_REDIS_HOST=cache
      - TZ=Europe/Moscow
    ports:
      - "8080:8080"
    networks:
      - app-network
    depends_on:
      - db
      - cache
    volumes:
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped

networks:
  app-network:
    driver: bridge

volumes:
  db:
    driver: local
  cache:
    driver: local
